//
//  TTUserModel.m
//  ExhibitionHall
//
//  Created by 王洋 on 2019/6/15.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "TTUserModel.h"

@interface TTUserModel ()


@end

@implementation TTUserModel

+ (TTUserModel *)sharedObject {
    static TTUserModel *shareInstance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        
        shareInstance = [TTUserModel new];
    });
    return shareInstance;
}

- (void)initialization {
    
    self.userName = @"";
    self.userIconURL = @"";
    self.accessToken = @"";
    self.userID = @"";
    self.recommandCode = @"";
    
    [self.userModelDefault setValue:@"" forKey:@"access_token"];
    [self.userModelDefault setValue:@"" forKey:@"uer_name"];
    [self.userModelDefault setValue:@"" forKey:@"user_icon"];
    [self.userModelDefault setValue:@"" forKey:@"user_id"];
    [self.userModelDefault setValue:@"" forKey:@"user_recommandCode"];
    [self.userModelDefault setValue:@(Comment_Verify_Unknow) forKey:@"user_vertify"];

    [self.userModelDefault setValue:@"unLoged" forKey:@"login_status"];
    [self.userModelDefault synchronize];

}

- (PP_UserVerifyType)verifyType {
    _verifyType = (PP_UserVerifyType)[[self.userModelDefault valueForKey:@"user_vertify"] integerValue];
    return _verifyType;
}

//判断是否已经登录
- (BOOL)isLogged {
    if([self.loginStatus isEqualToString:@"unLoged"])
    {
        return NO;
    }
    return YES;
}

- (NSString *)loginStatus {
    
    NSString *login_status = [self.userModelDefault valueForKey:@"login_status"];
    if (!login_status.length) {
        login_status = @"unLoged";
    }
    return login_status;
}

- (NSString *)userLoginAccount {
    NSString *userAccount = [self.userModelDefault valueForKey:@"PP_user_account"];
    if (!userAccount.length) {
        userAccount = @"";
    }
    return userAccount;
}

- (NSString *)recommandCode {
    NSString *recommandCode = [self.userModelDefault valueForKey:@"user_recommandCode"];
    if (!recommandCode.length) {
        recommandCode = @"";
    }
    return recommandCode;
}

- (NSString *)userLoginPSW {
    NSString *userPSW = [self.userModelDefault valueForKey:@"PP_user_password"];
    if (!userPSW.length) {
        userPSW = @"";
    }
    return userPSW;
}

- (BOOL)isSaveAccountAndPassword {
    NSString *isSave = [self.userModelDefault valueForKey:@"PP_issaveaccount"];
    if ([isSave isEqualToString:@"1"]) {
        _isSaveAccountAndPassword = YES;
    } else {
        _isSaveAccountAndPassword = NO;
    }
    return _isSaveAccountAndPassword;
}

- (NSString *)accessToken {
    
    NSString *access_token =[self.userModelDefault valueForKey:@"access_token"];
    if (!access_token.length) {
        access_token = @"Basic Zm9vOmJhcg==";
    }
    return access_token;
}

- (NSString *)userName {
    NSString *user_name = [self.userModelDefault valueForKey:@"uer_name"];
//    if (!user_name.length) {
//        user_name = @"未获取到用户名";
//    }
    return user_name;
}

- (NSString *)userID {
    NSString *user_id = [self.userModelDefault valueForKey:@"uer_id"];
    if (!user_id.length) {
        user_id = @"";
    }
    return user_id;
}

-(NSString *)userIconURL {
    NSString *user_icon = [self.userModelDefault valueForKey:@"user_icon"];
    return user_icon;
}

-(NSUserDefaults *)userModelDefault {
    if (!_userModelDefault) {
        _userModelDefault = [NSUserDefaults standardUserDefaults];
    }
    return _userModelDefault;
}


@end
